package view.Validator;

import javafx.scene.control.Control;
import javafx.scene.control.TextField;

import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.Validator;

import enums.Message;

/**
 * Provides an <code>Validator</code> which checks if the given input is valid (matches a-z, A-Z, ., , Umlaute).
 * @version %I%, %G%
 *
 */
public class NameValidator implements Validator<String> {

	@Override
	public ValidationResult apply(Control t, String u) {
		ValidationResult res = new ValidationResult();
		if(t instanceof TextField){
			String text = ((TextField) t).getText();
			if(text.matches("^.*[^a-zA-Z0-9. äüöß].*$")){
				res.addErrorIf(t, Message.NAMEVALIDATOR.toString(), true);
			}
		}
		return res;
	}
}
